﻿#include <QFile>
#include <QMenu>
#include "CInspectionListWidget.h"
#include "CHeader.h"
#include "CLogOper.h"
#include "CSqlOper.h"
CInspectionListWidget::CInspectionListWidget(QString sSceneGuid, CRBaseData* pBasicData, CDevBase* pDev, QWidget *parent)
	: m_sGuid(sSceneGuid),m_pBasicData(pBasicData), m_pDev(pDev),QWidget(parent)
{
	ui.setupUi(this);
	m_nFormNumber = 1;//表格序号
	ui.tableView->setContextMenuPolicy(Qt::CustomContextMenu);
	//setStyleSheetFile();
	initConnect();
	initTableView();
	initData();
	m_pTimer = new QTimer(this);
	m_pTimer->setTimerType(Qt::TimerType::PreciseTimer);
	connect(m_pTimer, &QTimer::timeout, this, &CInspectionListWidget::slotDataRefresh);
}

CInspectionListWidget::~CInspectionListWidget()
{
	if (m_pTimer != NULL)
	{
		if (m_pTimer->isActive())
		{
			m_pTimer->stop();
		}
		delete m_pTimer;
		m_pTimer = NULL;
	}
	if (m_pModel != NULL)
	{
		delete m_pModel;
		m_pModel = NULL;
	}
}

void CInspectionListWidget::refreshList()
{
	initData();

	//刷新状态
	if (m_pBasicData->m_pMutex->tryLock(200))
	{
		CDevDataBase* pDevDataRobot = (CDevDataBase*)m_pDev->m_pDevDataBase;
		CDevDataCam* pDataDevCamera = pDevDataRobot->m_pDevDataCam;
		int nCount = m_pBasicData->m_pTaskExecInfo->m_vecPolItemCom.size();//首先遍历各个巡检点的巡检项
		if (nCount > 0)
		{
			for (int i = 0; i < m_pBasicData->m_pTaskExecInfo->m_vecPolItemCom.size(); i++)
			{
				SCPolItemCom* pPolItemCom = m_pBasicData->m_pTaskExecInfo->m_vecPolItemCom[i];
				QList<QStandardItem*> item;
				bool bIsAlarm = false;//是否存在报警
				QString sItemResultGuid = pPolItemCom->m_ItemResult->m_sItemResultGuid;
				if (pPolItemCom->m_bIsAction == true && !m_mapItemId.contains(sItemResultGuid))//处理调用返回类型的
				{
					if (pPolItemCom->m_ItemResult->m_nDevType == enOntology)//本体
					{
						CItemResultSensor *pItemResultSensor = (CItemResultSensor *)pPolItemCom->m_ItemResult;//addwxy

						//item.append(new QStandardItem(QString::number(m_pModel->rowCount())));//序号
						item.append(new QStandardItem(QString::number(m_nFormNumber)));//序号
						item.append(new QStandardItem(m_mapTaskInfo.value(pItemResultSensor->m_sTaskGuid)));//任务名称
						item.append(new QStandardItem(pItemResultSensor->m_sItemName));//巡检项名称
						item.append(new QStandardItem(m_mapItemType.value(pItemResultSensor->m_nDevTypeCode)));//巡检项类型
						item.append(new QStandardItem(pItemResultSensor->m_dActionTime.toString("MM-dd-hh:mm:ss")));//时间
						item.append(new QStandardItem(QString::number(pItemResultSensor->m_dValue) + m_mapUnit[pItemResultSensor->m_nDevTypeCode]));//巡检结果
						if (pItemResultSensor->m_nState != 0 && pItemResultSensor->m_nState != -10)//证明有报警
						{
							bIsAlarm = true;
						}
						m_nFormNumber++;

						//记录日志
						SDevExecLog sDevExecLog;
						sDevExecLog.m_sDevName = A2T("巡检项");
						sDevExecLog.m_dLogTime = QDateTime::currentDateTime();
						if (bIsAlarm)
						{
							QString sAlmLimit = "";//报警限
							switch (pItemResultSensor->m_nState)
							{
							case -2:
								sAlmLimit = pItemResultSensor->m_sDataThreadHoldLL;
								break;
							case -1:
								sAlmLimit = pItemResultSensor->m_sDataThreadHoldL;
								break;
							case 1:
								sAlmLimit = pItemResultSensor->m_sDataThreadHoldH;
								break;
							case 2:
								sAlmLimit = pItemResultSensor->m_sDataThreadHoldHH;
								break;
							default:
								break;
							}
							sDevExecLog.m_sDescriptionl = A2T("%1m位置发生%2传感器巡检项报警,检测值%3,报警限%4")
								.arg(QString::number(pItemResultSensor->m_dRealLocation))
								.arg(pItemResultSensor->m_sItemName)
								.arg(QString::number(pItemResultSensor->m_dValue, 'f', 2))
								.arg(sAlmLimit);
							sDevExecLog.m_nAlarmLevel = enProcessAlarm;
						}
						else
						{
							sDevExecLog.m_sDescriptionl = A2T("%1m位置进行%2传感器巡检项检测,未报警,检测值%3")
								.arg(QString::number(pItemResultSensor->m_dRealLocation))
								.arg(pItemResultSensor->m_sItemName)
								.arg(QString::number(pItemResultSensor->m_dValue, 'f', 2));
							sDevExecLog.m_nAlarmLevel = enWorkInfo;
						}
						pDevDataRobot->addDevExecLog(sDevExecLog);
					}
					else if (pPolItemCom->m_ItemResult->m_nDevType == enSubDev1)//云台 addwxy
					{
						//云台数据
						CItemResultCamera *pItemResultCamer = (CItemResultCamera *)pPolItemCom->m_ItemResult;
						CPolItemCamer* pPolItemCamer = (CPolItemCamer*)pPolItemCom->m_pPolItem;
						//首先如果是持续监测主动上报的巡检项，则跳过，后边再处理
						if (pPolItemCamer->m_nCheckType == 1)
						{
							continue;
						}
						//这里要根据不同的云台巡检项分类处理
						if (pItemResultCamer->m_nDevTypeCode == enIR)//红外相机
						{
							//item.append(new QStandardItem(QString::number(m_pModel->rowCount())));//序号
							item.append(new QStandardItem(QString::number(m_nFormNumber)));//序号
							item.append(new QStandardItem(m_mapTaskInfo.value(pItemResultCamer->m_sTaskGuid)));//任务名称
							item.append(new QStandardItem(pItemResultCamer->m_sItemName));//巡检项名称
							item.append(new QStandardItem(m_mapItemType.value(pItemResultCamer->m_nDevTypeCode)));//巡检项类型
							item.append(new QStandardItem(pItemResultCamer->m_dActionTime.toString("MM-dd-hh:mm:ss")));//时间
							item.append(new QStandardItem(QString::number(pItemResultCamer->m_dTempMax) + m_mapUnit[pItemResultCamer->m_nDevTypeCode]));//巡检结果(使用最高温度)
							if (pItemResultCamer->m_nState != 0 && pItemResultCamer->m_nState != -10)//证明有报警
							{
								bIsAlarm = true;
							}
							m_nFormNumber++;

							//记录日志
							SDevExecLog sDevExecLog;
							sDevExecLog.m_sDevName = A2T("巡检项");
							sDevExecLog.m_dLogTime = QDateTime::currentDateTime();
							if (bIsAlarm)
							{
								QString sAlmLimit = "0";//报警限
								switch (pItemResultCamer->m_nState)
								{
								case -2:
									sAlmLimit = pItemResultCamer->m_sDataThreadHoldLL;
									break;
								case -1:
									sAlmLimit = pItemResultCamer->m_sDataThreadHoldL;
									break;
								case 1:
									sAlmLimit = pItemResultCamer->m_sDataThreadHoldH;
									break;
								case 2:
									sAlmLimit = pItemResultCamer->m_sDataThreadHoldHH;
									break;
								default:
									break;
								}
								sDevExecLog.m_sDescriptionl = A2T("%1m位置,发生%2红外相机巡检项报警,检测值%3,报警限%4")
									.arg(QString::number(pItemResultCamer->m_dRealLocation))
									.arg(pItemResultCamer->m_sItemName)
									.arg(QString::number(pItemResultCamer->m_dTempMax, 'f', 2))
									.arg(sAlmLimit);
								sDevExecLog.m_nAlarmLevel = enProcessAlarm;
							}
							else
							{
								sDevExecLog.m_sDescriptionl = A2T("%1m位置,进行%2红外相机巡检项检测,未报警,检测值%3")
									.arg(QString::number(pItemResultCamer->m_dRealLocation))
									.arg(pItemResultCamer->m_sItemName)
									.arg(QString::number(pItemResultCamer->m_dTempMax, 'f', 2));
								sDevExecLog.m_nAlarmLevel = enWorkInfo;
							}
							pDevDataRobot->addDevExecLog(sDevExecLog);

						}
						else if (pItemResultCamer->m_nDevTypeCode == enCamer)//图像相机
						{
							//item.append(new QStandardItem(QString::number(m_pModel->rowCount())));//序号
							item.append(new QStandardItem(QString::number(m_nFormNumber)));//序号
							item.append(new QStandardItem(m_mapTaskInfo.value(pItemResultCamer->m_sTaskGuid)));//任务名称
							item.append(new QStandardItem(pItemResultCamer->m_sItemName));//巡检项名称
							item.append(new QStandardItem(m_mapItemType.value(pItemResultCamer->m_nDevTypeCode)));//巡检项类型
							item.append(new QStandardItem(pItemResultCamer->m_dActionTime.toString("MM-dd-hh:mm:ss")));//时间
							item.append(new QStandardItem(pItemResultCamer->m_sIRUrl));//图像相机展示路径
							if (pItemResultCamer->m_nState != 0 && pItemResultCamer->m_nState != -10)//证明有报警
							{
								bIsAlarm = true;
							}
							m_nFormNumber++;

							//记录日志
							SDevExecLog sDevExecLog;
							sDevExecLog.m_sDevName = A2T("巡检项");
							sDevExecLog.m_dLogTime = QDateTime::currentDateTime();
							if (bIsAlarm)
							{
								sDevExecLog.m_sDescriptionl = A2T("%1m位置,发生%2图像相机巡检项报警")
									.arg(QString::number(pItemResultCamer->m_dRealLocation))
									.arg(pItemResultCamer->m_sItemName);
								sDevExecLog.m_nAlarmLevel = enProcessAlarm;
							}
							else
							{
								sDevExecLog.m_sDescriptionl = A2T("%1m位置,进行%2图像相机巡检项检测,未报警")
									.arg(QString::number(pItemResultCamer->m_dRealLocation))
									.arg(pItemResultCamer->m_sItemName);
								sDevExecLog.m_nAlarmLevel = enWorkInfo;
							}
							pDevDataRobot->addDevExecLog(sDevExecLog);

						}
						else if (pItemResultCamer->m_nDevTypeCode == enVoice)//声音传感器
						{
							//item.append(new QStandardItem(QString::number(m_pModel->rowCount())));//序号
							item.append(new QStandardItem(QString::number(m_nFormNumber)));//序号
							item.append(new QStandardItem(m_mapTaskInfo.value(pItemResultCamer->m_sTaskGuid)));//任务名称
							item.append(new QStandardItem(pItemResultCamer->m_sItemName));//巡检项名称
							item.append(new QStandardItem(m_mapItemType.value(pItemResultCamer->m_nDevTypeCode)));//巡检项类型
							item.append(new QStandardItem(pItemResultCamer->m_dActionTime.toString("MM-dd-hh:mm:ss")));//时间
							item.append(new QStandardItem(QString::number(pItemResultCamer->m_dValue) + m_mapUnit[pItemResultCamer->m_nDevTypeCode]));//声音传感器使用分贝值
							if (pItemResultCamer->m_nState != 0 && pItemResultCamer->m_nState != -10)//证明有报警
							{
								bIsAlarm = true;
							}
							m_nFormNumber++;

							//记录日志
							SDevExecLog sDevExecLog;
							sDevExecLog.m_sDevName = A2T("巡检项");
							sDevExecLog.m_dLogTime = QDateTime::currentDateTime();
							if (bIsAlarm)
							{
								QString sAlmLimit = "0";//报警限
								switch (pItemResultCamer->m_nState)
								{
								case -2:
									sAlmLimit = pItemResultCamer->m_sDataThreadHoldLL;
									break;
								case -1:
									sAlmLimit = pItemResultCamer->m_sDataThreadHoldL;
									break;
								case 1:
									sAlmLimit = pItemResultCamer->m_sDataThreadHoldH;
									break;
								case 2:
									sAlmLimit = pItemResultCamer->m_sDataThreadHoldHH;
									break;
								default:
									break;
								}
								sDevExecLog.m_sDescriptionl = A2T("%1m位置,发生%2声音检测巡检项报警,检测值%3,报警限%4")
									.arg(QString::number(pItemResultCamer->m_dRealLocation))
									.arg(pItemResultCamer->m_sItemName)
									.arg(QString::number(pItemResultCamer->m_dValue, 'f', 2))
									.arg(sAlmLimit);
								sDevExecLog.m_nAlarmLevel = enProcessAlarm;
							}
							else
							{
								sDevExecLog.m_sDescriptionl = A2T("%1m位置,进行%2声音检测巡检项检测,未报警,检测值%3")
									.arg(QString::number(pItemResultCamer->m_dRealLocation))
									.arg(pItemResultCamer->m_sItemName)
									.arg(QString::number(pItemResultCamer->m_dValue, 'f', 2));
								sDevExecLog.m_nAlarmLevel = enWorkInfo;
							}
							pDevDataRobot->addDevExecLog(sDevExecLog);
						}
					}

					//设置居中显示
					for (int nRow = 0; nRow < item.count(); nRow++)
					{
						item.at(nRow)->setTextAlignment(Qt::AlignCenter);
						if (bIsAlarm)
						{
							item.at(nRow)->setForeground(QBrush(QColor(255, 0, 0)));
						}
						else
						{
							item.at(nRow)->setForeground(QBrush(QColor(255, 255, 255)));
						}
					}
					if (item.size() > 0)
					{
						m_pModel->insertRow(0, item);
					}
					//pPolItemCom->m_bIsShow = true;
					m_mapItemId.insert(sItemResultGuid, sItemResultGuid);
					if (m_pModel->rowCount() > 500)
					{
						m_pModel->removeRows(m_pModel->rowCount() - 1, 1);//移除最后一行
					}
				}
			}
			for (int i = 0; i < m_pBasicData->m_pTaskExecInfo->m_vecPolItemCom.size(); i++)//
			{
				SCPolItemCom* pPolItemCom = m_pBasicData->m_pTaskExecInfo->m_vecPolItemCom[i];
				if (pPolItemCom->m_pPolItem->m_nDevType == enSubDev1)
				{
					CPolItemCamer* pPolItemCamer = (CPolItemCamer*)pPolItemCom->m_pPolItem;
					if (pPolItemCamer->m_nCheckType == 1 && (pPolItemCamer->m_nCollectIndex == 0 || pPolItemCamer->m_nCollectIndex == 2))
					{
						for (int j = 0; j < pPolItemCom->m_vecItemResult.size(); j++)
						{
							//云台数据
							CItemResultCamera *pItemResultCamer = (CItemResultCamera *)pPolItemCom->m_vecItemResult[j];
							QList<QStandardItem*> item;
							bool bIsAlarm = false;//是否存在报警
							QString sItemResultGuid = pItemResultCamer->m_sItemResultGuid;
							if (m_mapItemId.contains(sItemResultGuid))
							{
								continue;
							}
							//这里要根据不同的云台巡检项分类处理
							if (pItemResultCamer->m_nDevTypeCode == enIR)//红外相机
							{
								item.append(new QStandardItem(QString::number(m_nFormNumber)));//序号
								item.append(new QStandardItem(m_mapTaskInfo.value(pItemResultCamer->m_sTaskGuid)));//任务名称
								item.append(new QStandardItem(pItemResultCamer->m_sItemName));//巡检项名称
								item.append(new QStandardItem(A2T("红外相机持续监测")));//巡检项类型
								item.append(new QStandardItem(pItemResultCamer->m_dActionTime.toString("MM-dd-hh:mm:ss")));//时间
								item.append(new QStandardItem(QString::number(pItemResultCamer->m_dTempMax) + m_mapUnit[pItemResultCamer->m_nDevTypeCode]));//巡检结果(使用最高温度)
								if (pItemResultCamer->m_nAlarmLevel != 0)
								{
									bIsAlarm = true;
								}
								m_nFormNumber++;
								//记录日志
								SDevExecLog sDevExecLog;
								sDevExecLog.m_sDevName = A2T("巡检项");
								sDevExecLog.m_dLogTime = QDateTime::currentDateTime();
								QString sAlmLimit = "0";//报警限
								if (bIsAlarm)
								{
									switch (pItemResultCamer->m_nState)
									{
									case -2:
										sAlmLimit = pItemResultCamer->m_sDataThreadHoldLL;
										break;
									case -1:
										sAlmLimit = pItemResultCamer->m_sDataThreadHoldL;
										break;
									case 1:
										sAlmLimit = pItemResultCamer->m_sDataThreadHoldH;
										break;
									case 2:
										sAlmLimit = pItemResultCamer->m_sDataThreadHoldHH;
										break;
									default:
										break;
									}
									sDevExecLog.m_sDescriptionl = A2T("%1m位置,发生红外相机持续监测报警,检测值%2,报警限%3")
										.arg(QString::number(pItemResultCamer->m_dRealLocation))
										.arg(QString::number(pItemResultCamer->m_dTempMax, 'f', 2))
										.arg(sAlmLimit);
									sDevExecLog.m_nAlarmLevel = enProcessAlarm;
								}
								else
								{
									sDevExecLog.m_sDescriptionl = A2T("%1m位置,红外相机持续监测,未报警,检测值%2")
										.arg(QString::number(pItemResultCamer->m_dRealLocation))
										.arg(QString::number(pItemResultCamer->m_dTempMax, 'f', 2));
									sDevExecLog.m_nAlarmLevel = enWorkInfo;
								}
								pDevDataRobot->addDevExecLog(sDevExecLog);
							}
							else if (pItemResultCamer->m_nDevTypeCode == enVoice)//声音传感器
							{
								item.append(new QStandardItem(QString::number(m_nFormNumber)));//序号
								item.append(new QStandardItem(m_mapTaskInfo.value(pItemResultCamer->m_sTaskGuid)));//任务名称
								item.append(new QStandardItem(pItemResultCamer->m_sItemName));//巡检项名称
								item.append(new QStandardItem(A2T("声音持续检测")));//巡检项类型
								item.append(new QStandardItem(pItemResultCamer->m_dActionTime.toString("MM-dd-hh:mm:ss")));//时间
								item.append(new QStandardItem(QString::number(pItemResultCamer->m_dValue) + m_mapUnit[pItemResultCamer->m_nDevTypeCode]));//声音传感器使用分贝值
								if (pItemResultCamer->m_nAlarmLevel != 0)
								{
									bIsAlarm = true;
								}
								m_nFormNumber++;
								//记录日志
								SDevExecLog sDevExecLog;
								sDevExecLog.m_sDevName = A2T("巡检项");
								sDevExecLog.m_dLogTime = QDateTime::currentDateTime();
								QString sAlmLimit = "0";//报警限
								if (bIsAlarm)
								{
									switch (pItemResultCamer->m_nState)
									{
									case -2:
										sAlmLimit = pItemResultCamer->m_sDataThreadHoldLL;
										break;
									case -1:
										sAlmLimit = pItemResultCamer->m_sDataThreadHoldL;
										break;
									case 1:
										sAlmLimit = pItemResultCamer->m_sDataThreadHoldH;
										break;
									case 2:
										sAlmLimit = pItemResultCamer->m_sDataThreadHoldHH;
										break;
									default:
										break;
									}
									sDevExecLog.m_sDescriptionl = A2T("%1m位置,发生声音持续检测报警,检测值%2,报警限%3")
										.arg(QString::number(pItemResultCamer->m_dRealLocation))
										.arg(QString::number(pItemResultCamer->m_dValue, 'f', 2))
										.arg(sAlmLimit);
									sDevExecLog.m_nAlarmLevel = enProcessAlarm;
								}
								else
								{
									sDevExecLog.m_sDescriptionl = A2T("%1m位置,声音持续检测,未报警,检测值%2")
										.arg(QString::number(pItemResultCamer->m_dRealLocation))
										.arg(QString::number(pItemResultCamer->m_dValue, 'f', 2));
									sDevExecLog.m_nAlarmLevel = enWorkInfo;
								}
								pDevDataRobot->addDevExecLog(sDevExecLog);
							}
							m_mapItemId.insert(sItemResultGuid, sItemResultGuid);
							//pItemResultCamer->m_bIsShow = true;
							//设置居中显示
							for (int nRow = 0; nRow < item.count(); nRow++)
							{
								item.at(nRow)->setTextAlignment(Qt::AlignCenter);
								if (bIsAlarm)
								{
									item.at(nRow)->setForeground(QBrush(QColor(255, 0, 0)));
								}
								else
								{
									item.at(nRow)->setForeground(QBrush(QColor(255, 255, 255)));
								}
							}
							if (item.size() > 0)
							{
								m_pModel->insertRow(0, item);
							}
							if (m_pModel->rowCount() > 500)
							{
								m_pModel->removeRows(m_pModel->rowCount() - 1, 1);//移除最后一行
							}
						}
					}
				}
			}
		}
		m_pBasicData->m_pMutex->unlock();
	}
}

void CInspectionListWidget::setStyleSheetFile()
{
	QString sQssPath = ":/qss/styleSheet.css";
	QFile qss(sQssPath);
	qss.open(QFile::ReadOnly);
	this->setStyleSheet(qss.readAll());
}

void CInspectionListWidget::initConnect()
{
	connect(ui.tableView, &QTableView::customContextMenuRequested, this, &CInspectionListWidget::slotCustomContextMenu);
}

void CInspectionListWidget::initTableView()
{
	//禁止编辑
	ui.tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
	//单选行
	ui.tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
	//模式为单选
	ui.tableView->setSelectionMode(QAbstractItemView::SingleSelection);
	//行末尾自动拉伸填充
	ui.tableView->horizontalHeader()->setStretchLastSection(true);
	//左边序号列隐藏
	ui.tableView->verticalHeader()->setVisible(false);
	m_pModel = new QStandardItemModel(this);
	QStringList headerListAction;		//水平表头
	headerListAction << A2T("序号") << A2T("任务名称") << A2T("巡检项名称") <<
		A2T("巡检项类型") << A2T("时间") << A2T("巡检结果");

	QList<quint16> listColumnWidth;		//列宽
	listColumnWidth << 60 << 150 << 150 << 150 << 150;

	//设置列数
	m_pModel->setColumnCount(headerListAction.count());
	//设置表头
	m_pModel->setHorizontalHeaderLabels(headerListAction);
	ui.tableView->setModel(m_pModel);
	//设置列宽
	for (int i = 0; i < listColumnWidth.count(); i++)
	{
		ui.tableView->setColumnWidth(i, listColumnWidth.at(i));
	}
	
}

void CInspectionListWidget::initData()
{
	m_mapItemType.clear();
	m_mapTaskInfo.clear();
	m_mapTaskResult.clear();
	m_mapUnit.clear();
	m_mapItemType.insert(enCamer, A2T("图像相机"));
	m_mapItemType.insert(enIR, A2T("红外相机"));
	m_mapItemType.insert(enVoice, A2T("声音传感器"));
	m_mapItemType.insert(enCO, A2T("一氧化碳"));
	m_mapItemType.insert(enGas, A2T("可燃气体"));
	m_mapItemType.insert(enPM25, A2T("PM2.5"));
	m_mapItemType.insert(enPM10, A2T("PM10"));
	m_mapItemType.insert(enTemp, A2T("温度"));
	m_mapItemType.insert(enHum, A2T("湿度"));
	m_mapItemType.insert(enUltrasonic, A2T("超声波"));

	m_mapUnit.insert(enIR, A2T("℃"));
	m_mapUnit.insert(enVoice, A2T("db"));
	m_mapUnit.insert(enCO, A2T("ppm"));
	m_mapUnit.insert(enGas, A2T("ppm"));
	m_mapUnit.insert(enPM25, A2T("ug/m3"));
	m_mapUnit.insert(enPM10, A2T("ug/m3"));
	m_mapUnit.insert(enTemp, A2T("℃"));
	m_mapUnit.insert(enHum, A2T("%RH"));
	m_mapUnit.insert(enCamer, A2T(""));
	m_mapUnit.insert(enUltrasonic, A2T(""));

	//从数据库中查询任务信息，并将任务GUID与任务名称绑定
	QVector<QSqlRecord> vecRecord;
	QString sErrMsg = "";
	selectAllTaskInfo(m_sGuid, vecRecord, sErrMsg);
	for (int i = 0; i < vecRecord.size(); i++)
	{
		m_mapTaskInfo.insert(vecRecord[i].value("GUID").toString(), vecRecord[i].value("TASK_NAME").toString());
	}
	vecRecord.clear();
}

void CInspectionListWidget::slotDataRefresh()
{
	if (!isVisible())
	{
		return;
	}
	refreshList();
}

void CInspectionListWidget::slotCustomContextMenu(const QPoint &pos)
{
	// 在这里可以处理右键点击事件
	QMenu contextMenu(this);
	QAction action(A2T("清空列表"), this);
	contextMenu.addAction(&action);

	// 在当前位置显示右键菜单
	QPoint globalPos = ui.tableView->mapToGlobal(pos);
	QAction* pAction = contextMenu.exec(globalPos);
	if (pAction && pAction->text() == A2T("清空列表"))
	{
		m_pModel->removeRows(0, m_pModel->rowCount());
		m_nFormNumber = 1;
	}
}
